﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DiplomaWeb.Models.Student;

namespace DiplomaWeb.Models.OrderPractice
{
    public class StudentListPracticeViewModel
    {
        private List<StudentViewModel> students;

        public List<StudentViewModel> Students
        {
            get { return students ?? (students = new List<StudentViewModel>()); }
            set { students = value; }
        }

        public void ToViewModel(Diploma.Models.OrderPractice model)
        {
            if (model.IsVerify.HasValue && model.IsVerify.Value)
            {
                ToViewModelSaved(model);
            }
            else
            {
                ToViewModelNotSaved(model);
            }
        }

        private void ToViewModelNotSaved(Diploma.Models.OrderPractice model)
        {
            foreach (var item in model.Students)
            {
                Students.Add(new StudentViewModel(item));
            }
        }

        private void ToViewModelSaved(Diploma.Models.OrderPractice model)
        {
            foreach (var item in model.SaveStateOrderPractices)
            {
                Students.Add(new StudentViewModel(item));
            }
        }
    }
}